//
//  MineViewController.m
//  FruitsWholesaler
//
//  Created by sgone-2 on 15/11/16.
//  Copyright © 2015年 sgone. All rights reserved.
//

#import "MineViewController.h"
#import "MineColletionCell.h"

#import "MainHeaderCell.h"
#import "DoorMessage.h"

//跳转到其他页面信息
#import "SYQController.h"
#import "YYTJController.h"
#import "XTTZController.h"
#import "ZHAQController.h"
#import "TXController.h"
#import "DDHZController.h"
#import "SetViewController.h"
#import "PurchaseViewController.h"
#import "XGMMViewController.h"


@interface MineViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>



@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;


@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLabel.text = @"我  的";
//    self.backBtn.hidden = NO;
    
    self.backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 20, 60, 40)];
    [self.backBtn setTitle:@"设置" forState:UIControlStateNormal];
    [self.topView addSubview:self.backBtn];
    self.backBtn.titleLabel.font = [UIFont systemFontOfSize:17];
    
    [self.backBtn addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    //注册cell
    [self.collectionView registerNib:[UINib nibWithNibName:@"MineColletionCell" bundle:nil] forCellWithReuseIdentifier:@"MineColletionCell"];
    self.collectionView.backgroundColor = BACKGROUND2;
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;

    
    
    
    //注册header
    //注册headerView Nib的view需要继承UICollectionReusableView
    [self.collectionView registerNib:[UINib nibWithNibName:@"MainHeaderCell" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MainHeaderCell"];
    
    
    
    //注册footer的使用
    
    //注册footerView Nib的view需要继承UICollectionReusableView
    [self.collectionView registerNib:[UINib nibWithNibName:@"MainFooterCell" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"MainFooterCell"];
    
    

    
    
}


-(void)back:(id)sender

{

    SetViewController *set = [[SetViewController alloc]initWithNibName:nil bundle:nil];
    [self.navigationController pushViewController:set animated:YES];



}

//UICollectionViewDelegateAndDataSource 协议方法
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
    //返回1个section
}


//每一个section下有多少项
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}


//每一项cell被创建时调用的方法
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //必须自定义模板,重用cell
    MineColletionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MineColletionCell" forIndexPath:indexPath];
   
    //赋值
    UIImageView *imageView = (UIImageView *) [cell viewWithTag:1];
    UILabel *label = (UILabel *) [cell viewWithTag:2];
    
    NSString *imageName = [NSString stringWithFormat:@"%ld",(long)(indexPath.row+1)];
    imageView.image = [UIImage imageNamed:imageName];
    
    
    NSArray *arrayName  = @[@"生意圈",@"营业统计",@"系统通知",@"账户安全",@"提现",@"账单汇总"];
    
    label.font = [UIFont systemFontOfSize:16];
    
    //遍历赋值操作
    label.text  =[NSString stringWithFormat:@"%@",arrayName[indexPath.row]];
    
    
    
   
    cell.backgroundColor = [UIColor whiteColor];
    
    
    
    return cell;
    
 
    
    
    
    
}

//定义每个Section 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(1,1,1,1);//分别为上、左、下、右
}



//定义每个UICollectionViewCell 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake(ViewWidth /3 -2, ViewWidth /3 - 2 );
    
}



//每个item的行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 2;
}

//设置item 的列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;
{
    return 2;

}


//设置header
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{

    NSString *reuseIdentifier;
    if ([kind isEqualToString: UICollectionElementKindSectionHeader ])
    {
        reuseIdentifier = @"MainHeaderCell";
    }
    
    else
    {
   
        reuseIdentifier = @"MainFooterCell";
    
    
    }
    
    
    
   

    
    
    
    if ([kind isEqualToString:UICollectionElementKindSectionHeader])
        
    {
        
        
    MainHeaderCell *view10 =  [collectionView dequeueReusableSupplementaryViewOfKind :kind   withReuseIdentifier:reuseIdentifier   forIndexPath:indexPath];
    //添加修改信息的Button
    
  
//    view10.btnXG.backgroundColor = [UIColor whiteColor];
//    [view10.btnXG setImage:[UIImage imageNamed:@"edit1"] forState:UIControlStateNormal];
        
    [view10.btnXG setBackgroundImage:[UIImage imageNamed:@"edit1"] forState:UIControlStateNormal];
        
    [view10.btnXG addTarget:self action:@selector(xiugai:) forControlEvents:UIControlEventTouchUpInside];
    
    


    
    

    
    return view10;
        
    }
    else
             
    {
        
        UICollectionReusableView *view11 =  [collectionView dequeueReusableSupplementaryViewOfKind :kind   withReuseIdentifier:reuseIdentifier   forIndexPath:indexPath];
        
        view11.backgroundColor = BACKGROUND2;
        
        
        
        return view11;
        
    }
    
    
}




#pragma mark 进行跳转至门店信息修改
-(void)xiugai:(id)sender
{

  
    DoorMessage *DM = [[DoorMessage alloc]initWithNibName:nil bundle:nil];
    [DM setHidesBottomBarWhenPushed:YES];
    
    [self.navigationController pushViewController:DM animated:YES];


}




//返回头headerView的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    CGSize size={320,255};
    return size;
}

//返回头footerView的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
    CGSize size={320,60};
    return size;
}



//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
    
    
}


//选择了某个cell,点击cell跳转到另一个页面进行操作
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
//    [cell setBackgroundColor:[UIColor greenColor]];
    

    PurchaseViewController *purVC = [[PurchaseViewController alloc] initWithNibName:@"PurchaseViewController" bundle:nil];
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            
//            SYQController *syq = [[SYQController alloc]initWithNibName:nil bundle:nil];
//            
//            
//            [syq setHidesBottomBarWhenPushed:YES];
//            
//            
//            [self.navigationController pushViewController:syq animated:YES];
            
            
//            [self.view makeToast:@"程序员正在努力开发这个功能呢！"];
//            purVC.titleStr = @"生意圈";
//            purVC.lblStr = @" 暂无消息~";
            [purVC setHidesBottomBarWhenPushed:YES];
            [self.navigationController pushViewController:purVC animated:YES];
            
        }
        else if (indexPath.row == 1)
        {
        
            YYTJController *yytj = [[YYTJController alloc]initWithNibName:nil bundle:nil];
            
            [yytj setHidesBottomBarWhenPushed:YES];
            
            [self.navigationController pushViewController:yytj animated:YES];
        
        }
        else if (indexPath.row == 2)
        {
            
            XTTZController *xttz = [[XTTZController alloc]initWithNibName:nil bundle:nil];
            
            
            [xttz setHidesBottomBarWhenPushed:YES];
            
            
            [self.navigationController pushViewController:xttz animated:YES];
        
//         [self.view makeToast:@"程序员正在努力开发这个功能呢！"];
        
//            purVC.titleStr = @"系统通知";
////            purVC.lblStr = @" 暂无通知~";
//            [purVC setHidesBottomBarWhenPushed:YES];
//            [self.navigationController pushViewController:purVC animated:YES];
        }
        
        else if (indexPath.row == 3)
        {
        
//            ZHAQController *zhaq = [[ZHAQController alloc]initWithNibName:nil bundle:nil];
//            [zhaq setHidesBottomBarWhenPushed:YES];
//            [self.navigationController pushViewController:zhaq animated:YES];
        
        
        
        
        }
        
        else if (indexPath.row == 4)
        {
        
            TXController *tx = [[TXController alloc]initWithNibName:nil bundle:nil];
            
            
            [tx setHidesBottomBarWhenPushed:YES];
            
            
            [self.navigationController  pushViewController:tx animated:YES];
        
        
        
        }
        else
            
        {
        
        
            DDHZController *ddhz = [[DDHZController alloc]initWithNibName:nil bundle:nil];
            
            
            [ddhz setHidesBottomBarWhenPushed:YES];
            
            
            [self.navigationController pushViewController:ddhz animated:YES];
        
        
        }
        
        
    }
    

}








@end
